// pages/mine/service/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

    //模态框
    flag_contact: true,
    flag_contact_Two: true,
    role: app.register_info.register_role,
  },
  click_feedback() {
    wx.navigateTo({
      url: '../feedBack/index',
    })
  },
  go_detail(e) {
    // console.log(e)
    let answer = e.currentTarget.dataset.answer,
      question = e.currentTarget.dataset.question,
      qa_id = e.currentTarget.dataset.qa_id;
    wx.navigateTo({
      url: 'detail/index?answer=' + answer + '&question=' + question + '&qa_id=' + qa_id,
    })
  },
  //获取帮助列表
  helpList() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/vip/qa/list',
      data: {
        token: app.globalData.token
      },
      method: 'POST',
      success: (e) => {
        // console.log(e);
        let qa = e.data.data.qa,
          expire_time = e.data.data.expire_time ? parseInt(e.data.data.expire_time) : 0,
          sjcNow = app.globalData.sjcNow;
        expire_time = expire_time - parseInt(sjcNow);
        // console.log('expire_time+' + expire_time)
        // console.log('sjcNow+' + sjcNow)
        this.setData({
          qa: qa,
          expire_time: expire_time,
        });
      },
    })
  },
  //获取基础信息
  getInfo() {
    wx.request({
      url: app.globalData.url + 'api/common/register/info',
      data: {
        token: app.globalData.token,
      },
      method: 'POST',
      success: (e) => {
        console.log(e)
        let info = e.data.data.register_info;
        this.setData({
          info: info,
        })
      },
    })
  },
  //模态框 拨打
  click_phone: function() {
    wx.makePhoneCall({
      phoneNumber: '15267119021',
    })
    this.setData({
      flag_contact: true,
    })
  },
  //模态框 拨打
  click_phone_Two: function () {
    wx.makePhoneCall({
      phoneNumber: '0571-87081736',
    })
    this.setData({
      flag_contact_Two: true,
    })
  },
  //模态框 复制
  click_modal_copy_Two: function() {
    wx.setClipboardData({
      data: 'zhibozhijia888',
    })

  },
  click_service() {
    this.setData({
      flag_contact_Two: false,
    })
  },
  click_Vip_service() {
    let expire_time = this.data.expire_time;
    if (expire_time > 0) {
      this.setData({
        flag_contact: false,
      })
    } else {
      wx.showModal({
        content: '您还不是平台的VIP用户',
        showCancel: true,
        cancelText: '取消',
        cancelColor: '#333333',
        confirmText: '立即购买',
        confirmColor: '#d0a76c',
        success: function(e) {
          if (e.confirm) {
            wx.navigateTo({
              url: '../vip/index',
            })
          }
        }
      })
    }
  },
  modal_hide() {
    this.setData({
      flag_contact: true,
      flag_contact_Two: true,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.helpList();
    this.getInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})